package base.widgets;

import org.redr.canvas.OSPath;
import org.redr.canvas.RRW;
import org.redr.canvas.RedRApplication;
import org.redr.widgetGUI.core.TextEdit;
import org.redr.widgetGUI.settings.WidgetSettings;

import com.trolltech.qt.gui.QSizePolicy;
import com.trolltech.qt.gui.QTextOption;

import base.signals.RDataFrameInput;

public class Summary extends RRW{
	public static final String name = "Summary";
	public static final String summary = "Simple Summary";
	public static final String details = "Shows the result of the summary function.";
	public static final String icon = OSPath.join(RedRApplication.parentDir, "coreIcons", "default.png").getAbsolutePath();
    
	private TextEdit	mainEdit;
	public Summary(WidgetSettings ws) {
		super(ws);
		// TODO Auto-generated constructor stub
	}

	@Override
	protected void initSignals() {
		// TODO Auto-generated method stub
		this.addInput(new RDataFrameInput(this, "id1", _("Data Frame"), false));
	}

	@Override
	protected void initGUI() {
		// TODO Auto-generated method stub
		mainEdit = new TextEdit(this.gui.controlArea, (WidgetSettings) this.settings.getSettings("mainEdit")
				.setSetting("label", "Main Summary Box"));
		// mainEdit.widget().setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding);
		// mainEdit.widget().setMinimumWidth(400);
		mainEdit.widget().setFontFamily("courier");
		mainEdit.widget().setReadOnly(true);
		mainEdit.widget().setWordWrapMode(QTextOption.WrapMode.NoWrap);
	}

	@Override
	protected void dataInput(String id, Object data, String widgetId) {
		if (id.equals("id1")){
			// The method for id1, data frame
			try {
				String result = this.captureR(String.format("summary(%s)", (String) data));
				mainEdit.setText(result);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				return;
			}
		}
		
	}

	@Override
	protected void initVariables() {
		// TODO Auto-generated method stub
		
	}

}
